package com.fuwenhao.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.logging.Logger;

/**
 * @author fwh
 * @email fuwenhao594@163.com
 * @date 2019/7/25 下午5:08
 */
@RestController
public class HelloController {
    //    private final Logger logger = Logger.getLogger(String.valueOf(HelloController.class));
    @Autowired
    private DiscoveryClient client;

    /**
     * 注册服务地址为：fwh-ribbon-server
     *
     * @param
     * @return java.lang.String
     * @author fwh [2019/7/25 && 下午5:14]
     */
    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    public String index() {
        List<ServiceInstance> instances = client.getInstances("hello-service");
        for (int i = 0; i < instances.size(); i++) {
            System.out.println("/hello,host:" + instances.get(i).getHost() + ",service_id:" + instances.get(i).getServiceId());
//            logger.info("/hello,host:" + instances.get(i).getHost() + ",service_id:" + instances.get(i).getServiceId());
        }
        return "Hello World";
    }
}
